package cn.pzhu.javaee.demo.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.pzhu.javaee.demo.dao.TestObjectDao;
import cn.pzhu.javaee.demo.domain.TestObject;
import cn.pzhu.javaee.webapp.servlet.WebAppBaseServlet;
@WebServlet("/demo")
public class DemoServlet extends WebAppBaseServlet {	
	private static final long serialVersionUID = 519536771734131006L;
	
	private TestObjectDao toDao=new TestObjectDao();

	public DemoServlet() {
		
	}
	public void actionIndex(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			log.debug("Index");
			List<TestObject> toList=toDao.listAllTestObject();
			request.setAttribute("TObjList", toList);
			this.forward(request, response, "list.jsp");
			
	}
	 public void actionT1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			log.debug("actionT1");
			List<TestObject> toList=toDao.listAllTestObject();
			for(TestObject t:toList){
				log.debug(t.toString());
			}
	}
	 public void actionT2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			log.debug("actionT2");
			ServletContext sc=request.getServletContext();
			log.debug(sc.getContextPath());
			
	}
	 public void jsonT1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			log.debug("actionT1");
			List<TestObject> toList=toDao.listAllTestObject();
			for(TestObject t:toList){
				log.debug(t.toString());
			}
			this.sendJson(response, toList);
	}
	 
	 
}
